home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: newsfeed.internetmci.com!ncar!uchinews!news
- From: Michael Spertus<mps@geodesic.com>
- Subject: Re: Alignment of malloc()
- X-Nntp-Posting-Host: ford.uchicago.edu
- Message-ID: <DKo8ns.8A9@midway.uchicago.edu>
- Sender: news@midway.uchicago.edu (News Administrator)
- Organization: Dept. of Mathematics
- References: <DKDA7D.Kw7@midway.uchicago.edu> <j66Sx*FRe@yaps.rhein.de> <DKKHCH.L6r@midway.uchicago.edu> <4ccbdb$5v6@fg70.rz.uni-karlsruhe.de>
- Date: Thu, 4 Jan 1996 19:26:16 GMT
-
- In article <4ccbdb$5v6@fg70.rz.uni-karlsruhe.de>,
- Thomas Koenig <ig25@mvmap66.ciw.uni-karlsruhe.de> wrote:
- >
- >I know of no compiler which is as brain-damaged as the one you describe;
- >when I encounter one, I'd tend to howl to the vendor.
- >--
- Many PC compilers have this problem (See the BYTEmark column in the
- December BYTE). The problem is that Win32 GlobalAlloc(), which is
- what most allocators use to get their arenas, returns a 32-bit aligned
- pointer. Most standard library implementations will pass through this
- alignment (probably because the implementor does not realize that
- GlobalAlloc() does not align very well so that code for an sbrk()
- based allocator cannot be used without change. They may also be unaware
- that Pentium PCs use 64 bits data buses). This problem is magnified
- because the Pentium (apparently) drops into microcode on nonaligned
- loads, so that nonaligned floating point benchmarks are over 300%
- slower.
-
- Therefore, any code using floats must align all floating point malloc()
- to avoid running with abysmal efficiency on many of the most popular
- C/C++ compilers. I would like to believe that there should be an
- expectation that "malloc(float)" is a suitable or proper way to
- portably allocate a float ("suitable" and "proper" are the words used
- in the standard and reference documents to describe how malloc() should
- be aligned).
-
- In today's practice, I cannot do that. Hopefully, the BYTE article and
- maybe this thread will alert compiler vendors whose implementations
- don't align malloc() on float boundaries that their implementation is
- brain-damaged (your words) or not in the spirit of the standard (mine)
- and cause them to change their implementations. Until then, there is
- no way to write portable code that can be counted on to perform the
- simplest floating point operations without gross performance penalties.
-